﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;

using hou_elearning.Entity;
using hou_elearning.Business;
using hou_elearning.DataAccess.Base;

/// <summary>
/// Summary description for CheckLogin
/// </summary>
/// 
namespace hou_elearning.Custom
{
    public class CheckLogin : SqlProvider<NguoidungEntity>
    {
        static CheckLogin()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                NguoidungEntity entity = new NguoidungEntity();
				entity.PK_iNguoidungID = Int64.Parse("0"+dr["PK_iNguoidungID"].ToString());
				entity.sTendangnhap = dr["sTendangnhap"].ToString();
				entity.sMatkhau = dr["sMatkhau"].ToString();
				entity.sHoten = dr["sHoten"].ToString();
				entity.sEmail = dr["sEmail"].ToString();
				entity.sSodienthoai = dr["sSodienthoai"].ToString();
				entity.dNgaysinh =String.IsNullOrEmpty(dr["dNgaysinh"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaysinh"].ToString());
				entity.bGioitinh =String.IsNullOrEmpty(dr["bGioitinh"].ToString())?false:Boolean.Parse(dr["bGioitinh"].ToString());
				entity.sDiachi = dr["sDiachi"].ToString();
                return entity;
            };
        }
        public static NguoidungEntity isValidLogin(String strUsername, String strPassword)
        {
            string cmdName = "sp_tblNguoidung_Login";
            SqlParameter p1 = new SqlParameter("@sTendangnhap", strUsername);
            SqlParameter p2 = new SqlParameter("@sMatkhau", strPassword);
            NguoidungEntity entity = GetOne(cmdName, new SqlParameter[] { p1, p2 });
            return entity;
        }
    }
}